package com.wlb.test.util.rabbitmq;

import com.rabbitmq.client.Connection;
import com.rabbitmq.client.ConnectionFactory;

/**
 * @Author:wanglibing
 * @Mail:wanglibing@jd.com
 * @Date:Created in 21:01 2018/1/29
 * @Description:
 */
public class ConnectionUtil {
    public static Connection getConnection() throws Exception{
        ConnectionFactory factory = new ConnectionFactory();
//        设置服务地址
        factory.setHost("127.0.0.1");
//        端口
        factory.setPort(5672);
//        设置账号信息，密码用户名，Vhost
        factory.setVirtualHost("/test");
        factory.setUsername("admin");
        factory.setPassword("admin");
//        通过工程获取连接
        Connection connection = factory.newConnection();
        return connection;
    }
}
